package com.s666.demo.common.validate;

import lombok.extern.slf4j.Slf4j;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * @author 孙广岩
 */
@Slf4j
public class CheckMobileValidator implements ConstraintValidator<CheckMobile,String> {
    @Override
    public void initialize(CheckMobile checkCase) {

    }

    @Override
    public boolean isValid(String mobile, ConstraintValidatorContext constraintValidatorContext) {
        if( mobile == null ){
            return true;
        }
        //检验中国手机号
        String mobileChina = mobile;
        String regexChina ="^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if(mobileChina.matches(regexChina)){
            return true;
        }
        return  false;
    }
}
